<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use DB;
use Storage;
use File;

class HomeController extends BaseController
{
    public function index()
    {
    	return view(getThemeView('home.index'));
    }

    // 留言信息提交处理
    public function note(Request $request) {   
        $notedata = []; 
        $notedata['title'] = $request->input('title');
        $notedata['email'] = $request->input('email');
        $notedata['content'] = $request->input('content');
        $notedata['username'] = auth()->user()->name;
        $notedata['time'] = date('Y-m-d H:i:s',time());
        if ($notedata['title'] != '') {
            $res = DB::table('notes')->insert($notedata);
            if ($res) {
                return response()->json(array(
                        'res' => 1
                    ));
            }else {
                return response()->json(array(
                        'res' => 0
                    ));
            }
        }else {
            return response()->json(array(
                    'res' => 0
                ));
        }
    }

    // 测试路由
    public function test() {
    	return "success!";		
    }

    public function awardExcelDownload() {
        $name = '2018获奖成果Excel模板.xlsx';
        return response()->download(realpath(base_path('storage/app/public/properfiles')).'/award.xlsx', $name);
    }

    public function constrExcelDownload() {
        $name = '2018教学建设Excel模板.xlsx';
        return response()->download(realpath(base_path('storage/app/public/properfiles')).'/construction.xlsx', $name);
    }

    public function academicExcelDownload() {
        $name = '2018学术成果Excel模板.xlsx';
        return response()->download(realpath(base_path('storage/app/public/properfiles')).'/academic.xlsx', $name);
    }
}
